<?php
include_once($_SERVER['DOCUMENT_ROOT'] . '/smartrfid/helper/DBHelper.php');
class BaseModel {
  public $id;
  public $_table;
  
  function populateModel($dbRow) {
    foreach(array_keys($dbRow) as $property) {
      $this->$property = $dbRow[$property];
    }
  }
  
  function load($id) {
    $query = "SELECT * FROM `" . $this->_table . "` WHERE `id` = " . $id;
    $results = DBHelper::executeQuery($query);
    if(!$results) {
      return;
    }
    // we know there will be only one result
    $this->populateModel($results[0]);
    return $this;
  }
  
}